package implementation.sort;

import anaydis.sort.SorterType;
import com.sun.istack.internal.NotNull;
import implementation.sort.AbstractSorter;

import java.util.Comparator;
import java.util.List;


public class InsertionSort extends AbstractSorter {

    public InsertionSort() {
        super(SorterType.INSERTION);
    }

    public <T> void sort(@NotNull Comparator<T> tComparator, @NotNull List<T> ts) {
        for (int i = 1; i < ts.size(); i++) {
            int j = i;
            while (j > 0 && greater(tComparator, ts, j - 1, j)) {
                swap(ts, j, j - 1);
                j--;
            }
        }
    }



}
